package com.wbcs.system.intercept;

import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;

import com.wbcs.config.ConfigLoadManager;
import com.wbcs.exception.WbcsConfigLoadingException;

public abstract class AbsFileUploadInterceptor
{
    public final static String SAVEPATH_KEY="SAVEPATH";
    
    public final static String FILENAME_KEY="FILENAME";
    
    public final static String MAXSIZE_KEY="MAXSIZE";
    
    public final static String ALLOWTYPES_KEY="ALLOWTYPES";
    
    public final static String PAGEID_KEY="PAGEID";
    
    public final static String REPORTID_KEY="REPORTID";
    
    public final static String INPUTBOXID_KEY="INPUTBOXID";
    
    public final static String SAVEVALUE_KEY="SAVEVALUE";
    
    public boolean beforeDisplayFileUploadInterface(HttpServletRequest request,Map<String,String> mFormAndConfigValues,PrintWriter out)
    {
        return true;
    }

    public boolean beforeFileUpload(HttpServletRequest request,FileItem fileitemObj,Map<String,String> mFormAndConfigValues,PrintWriter out)
    {
        return true;
    }
    
    public boolean beforeDisplayFileUploadPrompt(HttpServletRequest request,List lstFieldItems,Map<String,String> mFormAndConfigValues,
            String failedMessage,PrintWriter out)
    {
        return true;
    }
    
    public static AbsFileUploadInterceptor createInterceptorObj(String interceptor)
    {
        if(interceptor==null||interceptor.trim().equals("")) return null;
        Object interObj=null;
        try
        {
            interObj=ConfigLoadManager.currentDynClassLoader.loadClassByCurrentLoader(interceptor.trim()).newInstance();
        }catch(Exception e)
        {
            throw new WbcsConfigLoadingException("文件上传拦截器"+interceptor+"类无法实例化",e);
        }
        if(!(interObj instanceof AbsFileUploadInterceptor))
        {
            throw new WbcsConfigLoadingException("文件上传拦截器"+interceptor+"类没有继承框架父类"+AbsFileUploadInterceptor.class.getName());
        }
        return (AbsFileUploadInterceptor)interObj;
    }
}
